package ocbn.remotelab.test_package;

/*
 * EventTest.java
 * JMUnit based test
 *
 * Created on 24-Nov-2009, 12:50:03 AM
 */



import ocbn.remotelab.events.*;
import java.util.Calendar;
import ocbn.remotelab.util.date.Date;
import jmunit.framework.cldc10.*;

/**
 * @author c9zhuron
 */
public class EventTest extends TestCase {
     private Event e1;
     private Event e2;
     private Event e3;
     private long id = 34567;
     private Calendar cal;
     private Date time;
     private Date eventCreationTime;
     private boolean isImportant = true;

    public EventTest() {
        //The first parameter of inherited constructor is the number
        //of test cases
        super(8,"EventTest");

        cal = Calendar.getInstance();
        cal.set(Calendar.YEAR, 2009);
        cal.set(Calendar.MONTH, 9);
        cal.set(Calendar.DAY_OF_MONTH, 3);
        cal.set(Calendar.HOUR, 10);
        cal.set(Calendar.AM_PM, Calendar.PM);
        cal.set(Calendar.MINUTE, 12);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);

        time = new Date(cal.getTime());

        e1 = new Event(id);
        eventCreationTime = new Date();
        e2 = new Event(id, time);
        e3 = new Event(id, time, isImportant);

    }

    public void test(int testNumber) throws Throwable {
        switch (testNumber) {
            case 0:
                testSetID();
                break;
            case 1:
                testGetType();
                break;
            case 2:
                testSetTime();
                break;
            case 3:
                testToString();
                break;
            case 4:
                testGetID();
                break;
            case 5:
                testIsImportant();
                break;
            case 6:
                testSetImportance();
                break;
            case 7:
                testGetTime();
                break;
            default:
                break;
        }
    }

    /**
     * Test of testSetID method, of class Event.
     */
    public void testSetID() throws AssertionFailedException {
        System.out.println("setID");
        Event instance = new Event(id);
        long newID = 9876;
        instance.setID(newID);
        assertEquals(newID, instance.getID());
    }

    /**
     * Test of testGetType method, of class Event.
     */
    public void testGetType() throws AssertionFailedException {

        System.out.println("getType");
        Event event = new Event(id);
        MassSpectrometerStateEvent msevent = new MassSpectrometerStateEvent();
        Event msevent2 = new MassSpectrometerStateEvent();

        assertEquals(Event.class, event.getType());
        assertEquals(MassSpectrometerStateEvent.class, msevent.getType());
        assertEquals(MassSpectrometerStateEvent.class,
                ((Event)msevent).getType());
        assertEquals(MassSpectrometerStateEvent.class, msevent2.getType());
    }

    /**
     * Test of testSetTime method, of class Event.
     */
    public void testSetTime() throws AssertionFailedException {
        System.out.println("setTime");
        Event instance = new Event(id);
        instance.setTime(time);
        assertEquals(time, instance.getTime());
    }

    /**
     * Test of testToString method, of class Event.
     */
    public void testToString() throws AssertionFailedException {
        System.out.println("toString");
        String str;

        str = "Event occured at " + e1.getTime()
                + " with the ID of " + e1.getID();
        assertEquals(str, e1.toString());

        str = "Event occured at " + e2.getTime()
                + " with the ID of " + e2.getID();
        assertEquals(str, e2.toString());

        str = "Important event occured at " + e3.getTime()
                + " with the ID of " + e3.getID();
        assertEquals(str, e3.toString());

    }
    

    /**
     * Test of testGetID method, of class Event.
     */
    public void testGetID() throws AssertionFailedException {
        System.out.println("getID");
        assertEquals(id, e1.getID());
        assertEquals(id, e2.getID());
        assertEquals(id, e3.getID());
    }

    /**
     * Test of testIsImportant method, of class Event.
     */
    public void testIsImportant() throws AssertionFailedException {
        System.out.println("isImportant");
        assertEquals(false, e1.isImportant());
        assertEquals(false, e2.isImportant());
        assertEquals(true, e3.isImportant());
    }

    /**
     * Test of testSetImportance method, of class Event.
     */
    public void testSetImportance() throws AssertionFailedException {
        System.out.println("setImportance");
        Event instance = new Event(id, time, true);
        assertEquals(true, e3.isImportant());

        instance.setImportance(false);
        assertEquals(false, instance.isImportant());
    }

    /**
     * Test of testGetTime method, of class Event.
     */
    public void testGetTime() throws AssertionFailedException {
        System.out.println("getTime");
        // Since eventCreationTime is set to the system time after e1 has
        // been initialized, its time may be a bit later than the time recorded
        // in e1
        assertTrue(eventCreationTime.getTime() - e1.getTime().getTime() <= 800);
        assertEquals(time, e2.getTime());
        assertEquals(time, e3.getTime());
    }
}
